package design_pattern.chain.cycleChain;

import java.util.LinkedList;
import java.util.List;


public class IntercepterChain implements Intercepter{
    List<Intercepter> chain = new  LinkedList<Intercepter>();
    Integer pointer = 0;
    
    public IntercepterChain addIntercepter(Intercepter intercepter){
	chain.add(intercepter);
	return this;
    }
    
    public List<Intercepter> moveIntercepter(Intercepter intercepter){
	chain.remove(intercepter);
	return this.chain;
    }

    @Override
    public void doIntercept(Request req, Response resp, IntercepterChain chain) {
	if(pointer == this.chain.size()) return ;
	
	Intercepter node = this.chain.get(pointer);
	pointer ++;
	node.doIntercept(req, resp, chain);
    }
   
}
